<?php
/**
 * Controller de compromissos.
 *
 * @author    Chavão <freela@chavao.net>
 * @copyright Copyright (c) 2011, Chavão
 * @version   0.1
 */

class CompromissoController extends AppController
{
    public $layout = null;

    /**
     * Controller criar
     * @access public
     */
    public function criar()
    {
    }
  
    /**
     * Controller listar
     * @access public
     */

    public function listar()
    {
        /**
        * @author    Fernanda Rebelatto <fernanda.rebelatto@gmail.com>
        */
        function ordenarPorHorario($obj1, $obj2) {
            if ($obj1['comp_hora_inicio'] < $obj2['comp_hora_inicio']) {
                return -1;
            } elseif ($obj1['comp_hora_inicio'] > $obj2['comp_hora_inicio']) {
                return +1;
            }
            return 0;
        }
        $arrAux = $this->Compromisso->all(array(
				'conditions'=>array('comp_data' => $this->data['data'], 'usua_id' => $_SESSION['usua_id'])));
        usort($arrAux, 'ordenarPorHorario');
        $this->set(array(
			'arrCompromisso'=>$arrAux,
			'data'=>date('d/m/Y',strtotime($this->data['data']))
        ));
    }
    /**
     * Controller salvar
     * @access public
     */
    public function salvar()
    {       
        $this->data['usua_id'] = $_SESSION['usua_id'];
        $this->data['comp_data'] = implode('-',array_reverse(explode('/',$this->data['comp_data'])));
        if($this->data['comp_alerta'] == "on")
            $this->data['comp_alerta'] = 1;
        else
            $this->data['comp_alerta'] = 0;
        $this->Compromisso->save($this->data);
        $this->redirect($this->data['pagina']);
    }
}

?>
